<?php
require_once 'common/init.php';
require_once 'config/conf.inc.php';

main();

function main()
{
	global $tpl;
	$err = "";

	$product_info = array();
	resolve_postdata($product_info);
	$ret = upload_title_image();
//var_dump($product_info);
	if (!$ret)
	{
		$err = "upload_err";
		$tpl->assign("error_msg", $err);
		$ret = $tpl->display('upload_ensure.html');
		return;
	}

	$ret = ProductManager::add_product($product_info, $err);
	$tpl->assign("error_msg", $err);
	$ret = $tpl->display('upload_ensure.html');
}

function upload_title_image()
{
	$img_file = $_FILES['UpLoadImage']["name"];
	$img_tmp_file = $_FILES['UpLoadImage']["tmp_name"];
	$target_path = "/home/horstonema/ntuan_cms/upload";
	$target_file = $target_path."/".$img_file;
	
	if (empty($img_tmp_file))	return;
	
	$ret = move_uploaded_file($img_tmp_file, $target_file);
	return $ret;
}

?>
